/**
 * Title: ScrollBanner.java
 * Description:
 * Copyright: Copyright (c) 2008
 * Company:深圳彩讯科技有限公司
 * Author 罗旭东 (hi@luoxudong.com)
 * Date 2013-12-16 下午12:19:53
 * Version 1.0
 */
package com.luoxudong.phonenumber.ui.widgets.scrollbanner;

import java.util.List;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import com.luoxudong.phonenumber.R;

/** 
 * ClassName: ScrollBanner
 * Description:滚动横幅
 * Create by 罗旭东
 * Date 2013-12-16 下午12:19:53
 */
public class ScrollBanner extends FrameLayout{
	private ViewFlow viewFlow = null;
	private ScrollBannerAdapter adapter = null;
	private Context context = null;
	
	public ScrollBanner(Context context) {
		super(context);
		init(context);
	}
	
	public ScrollBanner(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}
	
	public ScrollBanner(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		init(context);
	}
	
	private void init(Context context)
	{
		this.context = context;
		LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = mInflater.inflate(R.layout.scrollbanner_layout, null);
		viewFlow = (ViewFlow)view.findViewById(R.id.viewflow);
		
		CircleFlowIndicator indic = (CircleFlowIndicator) view.findViewById(R.id.viewflowindic);
        viewFlow.setFlowIndicator(indic);
        viewFlow.setTimeSpan(3000);
        //viewFlow.setSelection(0);	//设置初始位置
        viewFlow.startAutoFlowTimer();  //启动自动播放
        addView(view);
	}

	public void setImages(List<BannerItem> bannerItems)
	{
		adapter = new ScrollBannerAdapter(context, bannerItems);
		viewFlow.setAdapter(adapter);
		viewFlow.setmSideBuffer(bannerItems == null ? 0 : bannerItems.size());
		//invalidate();
		//adapter.notifyDataSetChanged();
		
	}
}
